<template>
  <div>
    <span class="status">{{ status }}</span>
  </div>
</template>

<script>
import { loadScript } from "@/utils/scriptLoader";
import JSW from "./jsw";
export default {
  name: "JswDemo",
  data() {
    return {
      serverData: {
        url: "",
        callType: 0,
      },
      user: {
        user: "admin",
        password: "123456",
      },
      status: "未初始化",
      jswClass: undefined,
      url: "",
    };
  },
  mounted() {
    this.init();
  },
  beforeDestroy() {
    jSW?.swDeInit();
  },
  methods: {
    async init() {
      console.log(123);
      const jSW = await loadScript({
        url: "",
        name: "jSW",
      });
      this.jSW = jSW;
      const jswClass = (this.jswClass = new JSW(jSW));
      await jswClass.swInit(this.serverData);
      this.status = "已初始化";

      const session = await jswClass.SWSession({
        server: "",
        port: 9701,
      });
      this.status = "会话已建立";
      await jswClass.login(this.user);
      this.status = "已登录";
      await jswClass.deviceList();
      const id = session._arr_pu[0]._id_pu;
      const channel = session.swGetPuChanel(id, 0);
      channel.swOpenEx({
        prototype: "hls",
        callback: () => {
          this.url = channel.swGetUrl().url;
          console.log(this.url);
        },
      });
    },
  },
};
</script>

<style lang="sass" scoped></style>
